﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ZhangBY.Entity
{

    /// <summary>
    /// 角色信息
    /// </summary>
    [Serializable]
    public class RolesInfo : ParentID
    {
        /// <summary>
        /// 角色名稱
        /// </summary>
        public String Name { get; set; }
    }

    /// <summary>
    /// 用戶與角色信息
    /// </summary>
    [Serializable]
    public class UserRolesInfo : ParentID
    {
        /// <summary>
        /// 用戶ID
        /// </summary>
        public String UserID { get; set; }

        /// <summary>
        /// 角色ID
        /// </summary>
        public String RolesID { get; set; }
    }

    /// <summary>
    /// 角色與權限信息
    /// </summary>
    [Serializable]
    public class RolesPermissionsInfo : ParentID
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public String RolesID { get; set; }
        /// <summary>
        /// 權限ID
        /// </summary>
        public String PermissionsID { get; set; }
    }

    /// <summary>
    /// 權限信息
    /// </summary>
    [Serializable]
    public class PermissionsInfo : ParentID
    {
        public int All { get; set; }
        /// <summary>
        /// 添加(0默認1接受2拒絕)
        /// </summary>
        public int Add { get; set; }
        /// <summary>
        /// 編輯更新(0默認1接受2拒絕)
        /// </summary>
        public int Edit { get; set; }
        /// <summary>
        /// 讀取(0默認1接受2拒絕)
        /// </summary>
        public int Read { get; set; }
        /// <summary>
        /// 刪除(0默認1接受2拒絕)
        /// </summary>
        public int Delete { get; set; }

    }

    /// <summary>
    /// 模塊信息
    /// </summary>
    [Serializable]
    public class ModuleInfo : ParentID
    {
        /// <summary>
        /// 模塊名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 模塊代號
        /// </summary>
        public string IndexName { get; set; }

    }

    /// <summary>
    /// 角色與模塊信息
    /// </summary>
    [Serializable]
    public class RolesModuleInfo : ParentID
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public String RolesID { get; set; }
        /// <summary>
        /// 模塊ID
        /// </summary>
        public String ModuleID { get; set; }
    }

    /// <summary>
    /// 完整權限信息類
    /// </summary>
    [Serializable]
    public class FullPermissionsInfo : IDisposable
    {
        RolesInfo m_rolesInfo = new RolesInfo();
        RolesModuleInfo m_rolesModuleIfo = new RolesModuleInfo();
        PermissionsInfo m_permissionsInfo = new PermissionsInfo();
        RolesPermissionsInfo m_rolesPermissionsInfo = new RolesPermissionsInfo();
        UserRolesInfo m_userRolesInfo = new UserRolesInfo();
        ModuleInfo m_moduleInfo = new ModuleInfo();
        /// <summary>
        /// 角色信息
        /// </summary>
        public RolesInfo RolesInfo
        {
            get { return m_rolesInfo; }
            set { m_rolesInfo = value; }
        }
        /// <summary>
        /// 角色與模塊信息
        /// </summary>
        public RolesModuleInfo RolesModuleInfo
        {
            get { return m_rolesModuleIfo; }
            set { m_rolesModuleIfo = value; }
        }
        /// <summary>
        /// 權限信息
        /// </summary>
        public PermissionsInfo PermissionsInfo
        {
            get { return m_permissionsInfo; }
            set { m_permissionsInfo = value; }
        }
        /// <summary>
        /// 角色與權限信息
        /// </summary>
        public RolesPermissionsInfo RolesPermissionsInfo
        {
            get { return m_rolesPermissionsInfo; }
            set { m_rolesPermissionsInfo = value; }
        }
        /// <summary>
        /// 用戶與角色
        /// </summary>
        public UserRolesInfo UserRolesInfo
        {
            get { return m_userRolesInfo; }
            set { m_userRolesInfo = value; }
        }
        /// <summary>
        /// 模塊信息
        /// </summary>
        public ModuleInfo ModuleInfo
        {
            get { return m_moduleInfo; }
            set { m_moduleInfo = value; }
        }

        #region 實現IDisposable
        private bool disposed = false;

        #region IDisposable 成员
        //可以被客户直接调用
        public void Dispose()
        {
            //必须以Dispose(true)方式调用,以true告诉Dispose(bool disposing)函数是被客户直接调用的
            Dispose(true);     // MUST be true
            // This object will be cleaned up by the Dispose method. Therefore, you should call GC.SupressFinalize to take this object off the finalization queue and prevent finalization code for this object from executing a second time.
            GC.SuppressFinalize(this); // 告诉垃圾回收器从Finalization队列中清除自己,从而阻止垃圾回收器调用Finalize方法.        
        }
        #endregion

        // 无法被客户直接调用
        // 如果 disposing 是 true, 那么这个方法是被客户直接调用的,那么托管的,和非托管的资源都可以释放
        // 如果 disposing 是 false, 那么函数是从垃圾回收器在调用Finalize时调用的,此时不应当引用其他托管对象所以,只能释放非托管资源
        protected virtual void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these operations, as well as in your methods that use the resource.
            // Check to see if Dispose has already been called
            if (disposed)
                return;
            if (disposing) // 这个方法是被客户直接调用的,那么托管的,和非托管的资源都可以释放
            {
                // 在这里释放托管资源
                RolesInfo = null;
                RolesModuleInfo = null;
                PermissionsInfo = null;
                RolesPermissionsInfo = null;
                UserRolesInfo = null;
                ModuleInfo = null;
            }

            // 在这里释放非托管资源
            disposed = true; // Indicate that the instance has been disposed
        }

        // 析构函数自动生成 Finalize 方法和对基类的 Finalize 方法的调用.默认情况下,一个类是没有析构函数的,也就是说,对象被垃圾回收时不会被调用Finalize方法
        ~FullPermissionsInfo()
        {
            // 为了保持代码的可读性性和可维护性,千万不要在这里写释放非托管资源的代码
            // 必须以Dispose(false)方式调用,以false告诉Dispose(bool disposing)函数是从垃圾回收器在调用Finalize时调用的
            Dispose(false);// MUST be false
        }
    }
        #endregion
}

